server {
    listen 80;
    server_name www.tizi.com tizi.com ziliao.tizi.com jia.tizi.com;
    
    root /space1/tizi;
    index index.html index.htm index.php;
    #if ($http_x_forwarded_for ~* 112.117.217.13) {
    #    return 200;
    # }
    #if ($remote_addr ~* 61.54.24.43|222.161.212.77) {
    #    return 200;
    # }
    
    rewrite ^/image/(.*) /application/views/static/image/$1 ;
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    access_log /var/log/nginx/tizi_access.log main;
    error_log /var/log/nginx/tizi_error.log;

    location = /favicon.ico {
    #    log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    if ($host = 'tizi.com' ) {
        rewrite ^/(.*)$ http://www.tizi.com/$1 permanent;
    }

    location /student {
        try_files $uri $uri/ /indexstudent.php?$args;
    }

    location /teacher {
        try_files $uri $uri/ /indexteacher.php?$args;
    }

    location /parent {
        try_files $uri $uri/ /indexparent.php?$args;
    }


    location / {
        try_files $uri $uri/ /index.php?$args;
    }


#    location  /student {
#	proxy_redirect off ;
#	proxy_set_header Host $host;
#	proxy_set_header X-Real-IP $remote_addr;
#	proxy_set_header REMOTE-HOST $remote_addr;
#	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#	client_max_body_size 50m;
#	client_body_buffer_size 256k;
#	proxy_connect_timeout 30;
#	proxy_send_timeout 30;
#	proxy_read_timeout 60;
#	proxy_buffer_size 256k;
#	proxy_buffers 4 256k;
#	proxy_busy_buffers_size 256k;
#	proxy_temp_file_write_size 256k;
#	proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
#	proxy_max_temp_file_size 128m;
#	proxy_pass    http://tizi.com;
#    }

   location ~ ^/application/(.*\.php)$ {
       fastcgi_param SCRIPT_FILENAME $request_filename;
       include fastcgi_params;
       fastcgi_read_timeout 3000;
       fastcgi_pass  unix:/dev/shm/phpapplication.socket;
       break;
       }

   location  ~ indexstudent\.php$ {
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
       fastcgi_intercept_errors on;
       fastcgi_read_timeout 3000;
       error_log /var/log/nginx/student_error.log;
       fastcgi_pass unix:/dev/shm/phpstudent.socket;
    }

   location  ~ indexteacher\.php$ {
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
       fastcgi_intercept_errors on;
       fastcgi_read_timeout 3000;
       error_log /var/log/nginx/teacher_error.log;
       fastcgi_pass unix:/dev/shm/phpteacher.socket;
    }

   location  ~ indexparent\.php$ {
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       include fastcgi_params;
       fastcgi_intercept_errors on;
       fastcgi_read_timeout 3000;
       error_log /var/log/nginx/parent_error.log;
       fastcgi_pass unix:/dev/shm/phpparent.socket;
    }

   location ~ index\.php$ {
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_intercept_errors on;
        fastcgi_read_timeout 3000;
        fastcgi_pass  unix:/dev/shm/php.socket;
    }
}
